package com.bwjf.authority.commons.base.entity;

import java.util.List;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import com.alibaba.fastjson.JSONObject;

/**
 * 结果
 * @author llq
 */
public class ResultMsg {
    private Boolean state=false;
    private String msg;
    
    
    public ResultMsg(BindingResult validResult){
        if(validResult.hasErrors()){
            List<ObjectError>  list = validResult.getAllErrors();
            this.state=false;
            this.msg=list.get(0).getDefaultMessage();
        }else{
            this.state=true;  
        }
    }
    
    public ResultMsg(boolean state,String msg){
        this.state=state;
        this.msg=msg;
    }
    
    public ResultMsg(boolean state,String successMsg,String errorMsg){
        this.state=state;
        this.msg=state?successMsg:errorMsg;
    }

    public Boolean getState() {
        return state;
    }

    public void setState(Boolean state) {
        this.state = state;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
    
    public String toJSONString(){
        return JSONObject.toJSONString(this);
    }
}
